define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'courierdetails/index' + location.search,
                    add_url: 'courierdetails/add',
                    edit_url: 'courierdetails/edit',
                    del_url: 'courierdetails/del',
                    multi_url: 'courierdetails/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'sort',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'mid', title: __('Mid')},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'pack', title: __('Pack'), operate:'BETWEEN'},
                        {field: 'coupon_id', title: __('Coupon_id')},
                        {field: 'payment', title: __('Payment'), searchList: {"0":__('Payment 0'),"1":__('Payment 1'),"2":__('Payment 2')}, formatter: Table.api.formatter.normal},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'shipping_fee', title: __('Shipping_fee')},
                        {field: 'orderid', title: __('Orderid')},
                        {field: 'order_time', title: __('Order_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7'),"8":__('Status 8')}, formatter: Table.api.formatter.status},
                        {field: 'sort', title: __('Sort')},
                        {field: 'site_id', title: __('Site_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});